package servletDemo;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet(name = "ServletPic", value = "/ServletPic")
public class ServletPic extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        FileInputStream fileInputStream = new FileInputStream("D:/Pictures/Sketchpad.png");
        ServletOutputStream servletOutputStream = response.getOutputStream();
        byte[] bytes =  new byte[1024];
        int len = 0;
        while ((len=fileInputStream.read(bytes))!=-1){
            servletOutputStream.write(bytes,0,len);
        }
        fileInputStream.close();
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
